package watcher

import (
	"encoding/json"
	"time"
	"watcher/client/config"
)

type Watcher interface {
	Watch() <-chan *WatchData
	Close()
}

type Option struct {
	Duration time.Duration
}

type WatcherRegister func(conf config.Conf) (string, Watcher, error)

type WatchData struct {
	Measurement string                 `json:"measurement"`
	Time        time.Time              `json:"time"`
	Fields      map[string]interface{} `json:"fields"`
	Tags        map[string]string      `json:"tags"`
}

func (w *WatchData) String() string {
	b, err := json.Marshal(w)
	if err != nil {
		return ""
	}
	return string(b)
}
